from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('http://101.133.169.100/yuns/index.php/')
title=driver.title #获取title名 赋值给一个变量
print(title)#输出title名字的文本信息
url=driver.current_url#获取url 赋值给一个变量
print(url)#输出url的文本信息
time.sleep(2)
driver.refresh() #对页面进行刷新
time.sleep(2)
driver.find_element_by_xpath("//a[text()='运动男鞋']/..").click()
time.sleep(2)
driver.back() #回退到上一页面
time.sleep(2)
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
# driver.maximize_window()  #把窗体最大化
# time.sleep(5)
# print(driver.get_window_size())  #输出窗体大小
# driver.set_window_size(600,300) #把窗体大小设置为固定大小，这里设置为宽600，高300的大小

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(5)
# driver.find_element_by_partial_link_text('阿里脱贫基金').click()

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888') #在这个输入框中输入18888888888
# time.sleep(3)
# driver.find_element_by_name('username').clear() #对这个输入框中的内容进行清空

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login')
# size=driver.find_element_by_name('username').size
# print(size) #获取某个控件的完整大小
# print(size['height'])  #获取某个控件的高
# print(size['width'])    #获取某个控件的宽

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login')
# text=driver.find_element_by_css_selector('div.bname>span').text #通过.text获取某个控件的文本信息，适用于获取两个标签中间加的文本内容，比如<span>用户登录</span>
# print(text)
# time.sleep(5)
# placeholder=driver.find_element_by_name('username').get_attribute('placeholder') #通过属性值获取某个控件的文本信息
# print(placeholder)

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/member/login')
# print(driver.find_element_by_css_selector('div.bname>span').is_displayed()) #判断控件是否加载完成

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/buy/index')
# time.sleep(10)
# driver.find_element_by_name('username').send_keys('18888888888')
# time.sleep(5)
# print(driver.find_element_by_name('username').get_attribute('value')) #判断输入框里内容是否与用户输入的一致

# 鼠标事件
# from selenium.webdriver.common.action_chains import ActionChains#从XXX中使用ActionChains方法
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/goods/37.html')
# time.sleep(5)
# dg = driver.find_element_by_xpath("//div[@class='wapbuycode']/a")#通过xpath定位到某一控件
# time.sleep(3)
# ActionChains(driver).move_to_element(dg).perform()#移动到该控件并且定格到该处，perform意思是让该条命令生效
# time.sleep(3)
# ActionChains(driver).context_click(dg).perform()#对该控件右击，perform意思是让该条命令生效
# time.sleep(3)
# ActionChains(driver).double_click(dg).perform()#对该控件双击，perform意思是让该条命令生效

# # 对控件进行拖动进行练习
# from selenium.webdriver.common.action_chains import ActionChains#从XXX中使用ActionChains方法
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://dun.163.com/trial/jigsaw')
# time.sleep(10)
# yzm=driver.find_element_by_css_selector('div.yidun_slider') #定位到需要拖动的控件，赋值给一个变量，方便下边引用
# a=driver.find_element_by_css_selector('img.yidun_jigsaw')
# ActionChains(driver).move_to_element(yzm).perform() #先定格到需要拖动的控件，否则会提示控件不可交互的报错
# time.sleep(5)
# ActionChains(driver).drag_and_drop_by_offset(yzm,208,0).perform() #拖动到具体的指定x,y坐标，右下为正，这样做不适用图片验证码，因为图片验证码每次图片位置都在变
# ActionChains(driver).drag_and_drop(yzm,a).perform()  # 拖动yzm控件到a控件的位置

# 键盘事件
# from selenium.webdriver.common.action_chains import ActionChains
# from selenium.webdriver.common.keys import Keys #先从XXX中导入Keys方法，方便下边调用
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# time.sleep(10)
# driver.find_element_by_name('key').send_keys('短袖')
# time.sleep(5)
# dw=driver.find_element_by_name('key')
# ActionChains(driver).double_click(dw).perform() #对输入框进行双击，选中内容
# time.sleep(2)
# dw.send_keys(Keys.CONTROL,'x')#对选中内容使用组合按键 ctrl+x 实现剪切
# time.sleep(2)
# dw.send_keys(Keys.CONTROL,'v')#对选中内容使用组合按键 ctrl+v 实现剪切
# time.sleep(2)
# dw.send_keys(Keys.ENTER) #实现回车键
# # driver.find_element_by_name('key').send_keys(Keys.BACKSPACE) #实现删除退格键
# # 按键很多输入Key.后会自动出来很多按键，选择自己需要的按键使用即可

# iframe嵌套练习
# from selenium.webdriver.common.action_chains import ActionChains
# from selenium.webdriver.common.keys import Keys #先从XXX中导入Keys方法，方便下边调用
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://mail.163.com/')
# dw=driver.find_element_by_css_selector('#loginDiv>iframe')  #先定位到iframe的位置
# driver.switch_to_frame(dw)  #再切入该模块进行操作，想要操作哪个iframe就要进入哪个iframe，如果有多个iframe，需要逐级切入
# driver.find_element_by_name('email').send_keys('qq807794272')
# driver.find_element_by_name('password').send_keys('zaq807794')
# driver.find_element_by_css_selector('#dologin').click()
driver.find_element_by_class_name()
# #select下拉选择框的练习
# from selenium.webdriver.support.select import Select
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://www.ctrip.com/')
# time.sleep(5)
# jd=driver.find_element_by_id('searchHotelLevelSelect')  #先定位到使用select的下拉框选择的控件
# fjs=driver.find_element_by_id('J_roomCountList') #先定位到使用select的下拉框选择的控件
# Select(fjs).select_by_index(2)   #根据下边索引去选择
# time.sleep(5)
# Select(jd).select_by_visible_text('四星级/高档') # 根据可见的文本信息去选择 <option>一般是这里的文字是可见的文本信息</option>
# time.sleep(5)
# Select(jd).select_by_value("2") #通过value去选择
